<?php
function seat_allocation() {
    $output = "";
    // dev 对应的就是参数dev的传值
    $output .= theme("seat_allocation");
    variable_set('is_start_full_page', TRUE);
    return $output;
}
//function handle_custom_register(){
//    $output='';
//    if(isset($_POST)&&!empty($_POST)){
//        $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
//        if(preg_match($pattern, $_POST['form']['email_address'])){
//           $result= db_select('sc_register', 'sc')
//            ->fields('sc')
//            ->condition('email_address', $_POST['form']['email_address'],'=') 
//            ->condition('sc_type',$_POST['sc_type'],'=')
//           ->execute()
//           ->fetchAssoc();
//            if(empty($result)){
//                $data['create_date']=time();
//                $data['update_date']=time();
//                $data['sc_type']=$_POST['sc_type'];
//               
//                if(isset($_POST['is_multiplayer'])&&$_POST['is_multiplayer']==2){ 
//                    $is_register=false;
//                    if(preg_match($pattern,$_POST['form2']['email_address'])){
//                         $result_form2= db_select('sc_register', 'sc')
//                        ->fields('sc')
//                        ->condition('email_address', $_POST['form2']['email_address'],'=')  
//                        ->condition('sc_type',$_POST['sc_type'],'=')
//                       ->execute()
//                       ->fetchAssoc();
//                         if(empty($result_form2)){
//                             $is_register=true;
//                         }else{
//                             $output .= theme("custom_register_theme_ty_page",array('dev'=>'Your friend has already registered (您的朋友已经注册过)'));
//           
//                          //   $output.="Your friend has already registered (您的朋友已经注册过)";
//                         }
//                    }else{
//                        $output .= theme("custom_register_theme_ty_page",array('dev'=>'Your friend email has been incorrectly formatting (您朋友的电子邮件格式不正确。)'));
//                        //$output.="Your friend email has been incorrectly formatting (您朋友的电子邮件格式不正确。)";
//                    }
//                    if($is_register){
//                            $data_form1=$data;
//                            $data_form2=$data;
//                            foreach($_POST['form'] as $key=>$val){
//                                $data_form1[$key]=$val;
//                            }
//                            foreach($_POST['form2'] as $key=>$val){
//                                $data_form2[$key]=$val;
//                            }
//
//                            $inser_id1=db_insert('sc_register')
//                          ->fields($data_form1)->execute();
//                            if(isset($inser_id1)){
//                                 $inser_id2=db_insert('sc_register')
//                                 ->fields($data_form2)->execute();
//                                 if(isset($inser_id1)&&isset($inser_id2)){
//                                     if($data_form1['email_address']==$data_form2['email_address']){
//                                         $first_name=$data_form1['first_name'].','.$data_form2['first_name'];
//                                          $qr_name='1:'.$data_form1['first_name'].'-'.$data_form1['last_name'].'2:'.$data_form2['first_name'].$data_form2['last_name'];
//                                          scregister_drupal_mail($qr_name,$data_form1['email_address'],$first_name,$_POST['sc_type']);
//                                          
//                                        //  $output.='email一样';
//                                     }else{
//                                         $qr_name1=$data_form1['first_name'].'-'.$data_form1['last_name'];
//                                         scregister_drupal_mail($qr_name1,$data_form1['email_address'],$data_form1['first_name'],$_POST['sc_type']);
//                                         $qr_name2=$data_form2['first_name'].'-'.$data_form2['last_name'];
//                                         scregister_drupal_mail($qr_name2,$data_form2['email_address'],$data_form2['first_name'],$_POST['sc_type']);
//                                    //     $output.='email不一样';
//                                     }
//                                     
//                                      $query = db_update('sc_register');
//                                      $query->fields(['qr_url'=> variable_get('qrcodePath'),'url'=> variable_get('albumurl')])->condition('rgid',$inser_id1)->execute();
//                                      db_update('sc_register')->fields(['qr_url'=> variable_get('qrcodePath'),'url'=> variable_get('albumurl')])->condition('rgid',$inser_id2)->execute();
//                        
//                                     
////                                    $output.='Multiplayer participation Registration Success (多人参与注册成功)';
//                                    // $output.='Thank you for registering the MOST SUCCESSFUL WOMEN 2018 AWARD DINNER on 22 June 2018.';
//                                     if($_POST['sc_type']=="LeadersForum2018"){
//                                         $output .= theme("custom_register_theme_tylf_page",array('dev'=>'修改这里Thank you for registering the MOST SUCCESSFUL WOMEN 2018 LEADERS FORUM on 22 June 2018. Tickets pre-order details will send to your email directly and please check the spam box or call 2202 5206 if you didn’t receive.'));
//                                     }else{
//                                          $output .= theme("custom_register_theme_ty_page",array('dev'=>'Thank you for registering the MOST SUCCESSFUL WOMEN 2018 AWARD DINNER on 22 June 2018. Please contact 2202 5206 if you have any inquiry and please check your spam box if you didn’t receive our event check-in letter.'));
//                                     }
//                                 }
//                            }else{
//                            $output .= theme("custom_register_theme_ty_page",array('dev'=>'Invalid input, contact administrator  Please contact 2202 5206 if you have any inquiry. (您的信息异常,请联系管理员)'));
//                         //   $output.='Invalid input, contact administrator (您的信息异常,请联系管理员)';
//                            }
//                    }
//                   
//                  
//                }else{
//                    foreach($_POST['form'] as $key=>$val){
//                       $data[$key]=$val;
//                    }
//                  
//                    $inser_id=db_insert('sc_register')
//                     ->fields($data)->execute();
//                 
//                    if(isset($inser_id)){
//                     // First we need to create the path for the img which will be generated as a png file. 
//                     // This will be automatically created using the code below
//                        $qr_name=$_POST['form']['first_name'].'-'.$_POST['form']['last_name'];
//                        scregister_drupal_mail($qr_name,$_POST['form']['email_address'],$_POST['form']['first_name'],$_POST['sc_type']);
//                        
//                     // $output.= $GLOBALS['base_url'].variable_get('qrcodePath');
//                      //注册成功;
//                         //$output .= theme("custom_register_theme_ty_page",array('dev'=>'Thank you for registering the MOST SUCCESSFUL WOMEN 2018 AWARD DINNER on 22 June 2018. Please contact 2202 5206 if you have any inquiry.'));
//                        //更新qr_code link
//                        $query = db_update('sc_register');
//                        $query->fields(['qr_url'=> variable_get('qrcodePath'),'url'=> variable_get('albumurl')])->condition('rgid',$inser_id)->execute();
//                        
//                        if($_POST['sc_type']=="LeadersForum2018"){
//                         $output .= theme("custom_register_theme_tylf_page",array('dev'=>'Thank you for registering the MOST SUCCESSFUL WOMEN 2018 LEADERS FORUM on 22 June 2018. Please send the bank-in slip to msw2018lf@scmedia.com and our colleague will re-confirm the seating to you after. Please call 2202 5206 if you have any inquiry.'));
//                        }else{
//                         $output .= theme("custom_register_theme_ty_page",array('dev'=>'Thank you for registering the MOST SUCCESSFUL WOMEN 2018 AWARD DINNER on 22 June 2018. Please contact 2202 5206 if you have any inquiry and please check your spam box if you didn’t receive our event check-in letter.'));
//                        }
//                         
//                         variable_set('is_start_full_page', TRUE);
//                         return $output; 
//                   // $output.='Thank you for registering the MOST SUCCESSFUL WOMEN 2018 AWARD DINNER on 22 June 2018.';
//                     }else{
//                       // $output.='Invalid input, contact administrator (您的信息异常,请联系管理员)';
//                         $output .= theme("custom_register_theme_ty_page",array('dev'=>'Invalid input, contact administrator  Please contact 2202 5206 if you have any inquiry. (您的信息异常,请联系管理员).'));
//                     
//                     }
//                
//                }
//                variable_set('is_start_full_page', TRUE);
//                return $output;
//            }else{
//                
//                if($_POST['sc_type']=="LeadersForum2018"){
//                       $output .= theme("custom_register_theme_tylf_page",array('dev'=>'Email address has been registered (电子邮件地址已经注册)'));
//                }else{
//                       $output .= theme("custom_register_theme_ty_page",array('dev'=>'Email address has been registered (电子邮件地址已经注册)'));
//                }          
//                variable_set('is_start_full_page', TRUE);
//                return $output;
//            }
//        }else{
//               if($_POST['sc_type']=="LeadersForum2018"){
//                       $output .= theme("custom_register_theme_tylf_page",array('dev'=>'INvalid email address format (您输入的电子邮件地址不合法)'));
//                }else{
//                       $output .= theme("custom_register_theme_ty_page",array('dev'=>'INvalid email address format (您输入的电子邮件地址不合法)'));
//                } 
//            variable_set('is_start_full_page', TRUE);
//            return $output;
//        }
//        
//       return 'you';
//    }else{
//     $url= base_path();
//      $output.=  '<script    type="text/javascript">';
//      $output.= "window.location.href='$url'";  
//      $output.= '</script>';
//    }
//    return $output;
//    
//}
//
///*
//*  create_qrcode
//*/
//
//function create_qrcode2($text , $qrpath) {
//  // Including the qrcode library and generating the code
//  include_once("sites/all/libraries/phpqrcode/qrlib.php");
//  QRcode::png($text, $qrpath);
//
//  return $qrpath;
//}
//
//function scregister_mail($key, &$message, $params) {
// // $email_array= explode("@",variable_get('emailTo'));
//  $email_address=preg_replace('/\W/','',variable_get('emailTo'));
//  $message_url='';
//  if(register_create_folder( getcwd().'/MSW/email/'.$email_address)){
//        $message_url=$GLOBALS['base_url'].'/MSW/email/'.$email_address;
//  }else{
//     $message_url=$GLOBALS['base_url'].'/MSW/email/'.$email_address;
//  }
//  variable_set('albumurl', $message_url);
//  switch ($key) {
//    case 'leaders':
//         $message['to'] = variable_get('emailTo');
//         $message['subject'] = t('MSW Registration Confirmation');
//         $message['body'][] = t('Dear @username,', array('@username' => $params['username']));
//         $message['body'][] = t('Please allow us to extend to you a warm thank you for joining the MOST SUCCESSFUL WOMEN 2018 LEADERS FORUM on 22 June 2018. ');
//         $message['body'][] = t('Please save this email and show the QR CODE priority pass to the event for registration check-in. ');
//         $message['body'][] = t('Once again, thank you for joining us at the LEADERS FORUM.');      
//         $message['body'][] = t('Best Regards,');
//         $message['body'][] = t('Connie Fan');
//         $message['body'][] = t('Marketing Department');
//         $message['body'][] = t('E: conniefan@scmedia.com.hk');
//         $message['body'][] = t('T: 2202 5206');
//         $message['body'][] = t('QR CODE priority pass :');
//         $message['body'][] = variable_get('qrcodePath');
//         $message['body'][] = t('Get back the event pictures? Click this:');
//         $message['body'][] = $message_url;
//         $message['headers']['Content-Type'] = 'text/plain; charset=UTF-8; format=flowed';   
//        break;
//    case 'award':
//      // Set headers etc
//      $message['to'] = variable_get('emailTo');
//      $message['subject'] = t('MSW Registration Confirmation');
//      $message['body'][] = t('Dear @username,', array('@username' => $params['username']));
//      $message['body'][] = t('Please allow us to extend to you a warm thank you for joining the MOST SUCCESSFUL WOMEN 2018 AWARD DINNER on 22 June 2018.');
//    //  $message['body'][] = t('AWARD DINNER on 22 June 2018.');
//      $message['body'][] = t('Please save this email and show the QR CODE priority pass to the event for registration check-in.');
//      $message['body'][] = t('Once again, thank you for joining us at the AWARD DINNER.');
//      $message['body'][] = t('Best Regards,');
//      $message['body'][] = t('Connie Fan');
//      $message['body'][] =t('Marketing Department');
//      $message['body'][] = t('E: conniefan@scmedia.com.hk');
//      $message['body'][] = t('T: 2202 5206');
//      //$message['body'][] = "&nbsp;&nbsp;";
//      $message['body'][] = t('QR CODE priority pass:');
//      $message['body'][] = variable_get('qrcodePath');
//      $message['body'][] = t('Get back the event pictures? Click this:');
//      $message['body'][] = $message_url;
//      $message['headers']['Content-Type'] = 'text/plain; charset=UTF-8; format=flowed';    
//      break;
//  }
//}
//
//
//function scregister_drupal_mail($qr_name,$email,$first_name,$meal) {
//    
//    $qrpath = variable_get('file_public_path', conf_path() . '/files') . "/scregister/images/" .time().rand(1,100).'.png'; 
//     // This is the  data to be added to the QR code.  
//     $text =$qr_name.'---'.$email;
//     if (!file_exists($qrpath)) {
//        $qrpath =  create_qrcode2($text , $qrpath);
//      }
//     // This will print the path to the image in a theme
//     $vars['qrimgpath'] = $qrpath;
//     $qrcodePath = $qrpath;
//     //$language = user_preferred_language($account);
//
//    $default_from = variable_get('site_mail', ini_get('sendmail_from'));
//    $emailTo=$email;
//    variable_set('emailTo', $emailTo);
//    variable_set('qrcodePath', $GLOBALS['base_url'].'/'.$qrcodePath);
//    //                    $language = user_preferred_language($user);
//    $language = language_default();
//    if($meal=='LeadersForum2018'){
//          drupal_mail('scregister', 'leaders',$email, $language, 
//     $params = array('username' => $first_name), 
//     $from = $default_from, 
//     $send = TRUE
//    );      
//    }else if($meal=='AwardDinner2018'){
//     drupal_mail('scregister', 'award',$email, $language, 
//     $params = array('username' => $first_name), 
//     $from = $default_from, 
//     $send = TRUE
//    ); 
//    }
//    
//   
//}
//
//function register_create_folder($email_name){
//     $dir = iconv("UTF-8", "GBK", $email_name);
//     $is_success=false;
//     if (!file_exists($dir)){
//         mkdir ($dir,0777,true);
//         $is_success=true;
//     } else {
//        $is_success=false;
//     }
//     return $is_success;
//}


